<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="btn">cliek me!</button>
    <a id="alink" href="https://tutorial.javascript.ac.cn/" target="_blank" rel="noopener noreferrer"></a>

    <script>
        function handleClick() {
            console.log('button clicked');
        }
        document.querySelector('#btn').addEventListener('click', function () {
            console.log('button clicked-------------');
        });
        document.querySelector('#btn').addEventListener('click', () => {
            alert('It was clicked!');
        });
        let btn = document.getElementById('btn');
        btn.addEventListener('click', handleClick)


        document.querySelector('#alink').addEventListener('click', function (e) {
            e.preventDefault();// 阻止默认行为
            console.log('link clicked');
        });

        document.querySelector('#alink').addEventListener('click', (e) => {
            e.stiopPropagation();// 阻止事件冒泡
            console.log('link clicked');
        });
        document.body.addEventListener('click', () => {
            console.log('body clicked'); // 事件冒泡

        });



    </script>
</body>

</html>